import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;

public class Header extends MainFrame
{

  /* Things on the Tabs*/
  JButton btnHome;
  JButton btnSettings;
  JButton btnPatients;
  JButton btnAppointments;
  JButton btnServices;
  
  /* Sub buttons */
  JButton btnChangePassword;
  JButton btnLogout;
  
  JButton btnViewPatients;
  JButton btnRegisterPatients;
  
  JButton btnViewAppointments;
  JButton btnScheduleNewAppointment;
  
  JButton btnViewServices;
  JButton btnAddNewService;
  
   public void Draw(){
         /* This area is for
         * the tabs
         * the software.
         */
        
        /* Go to Home Button */
        btnHome = new JButton(new ImageIcon("homeButton2.png"));
        btnHome.setBounds(0,108,86,60);
        btnHome.setBorderPainted(false);
        btnHome.setContentAreaFilled(false);
        btnHome.setRolloverIcon(new ImageIcon("homeButton.png"));
        btnHome.setPressedIcon(new ImageIcon("homeButton.png"));
        btnHome.addActionListener(new ButtonListener());

        
        /* Go to Settings Button */
        btnSettings = new JButton(new ImageIcon("settingsButton2.png"));
        btnSettings.setBounds(86,108,102,60);
        btnSettings.setBorderPainted(false);
        btnSettings.setContentAreaFilled(false);
        btnSettings.setRolloverIcon(new ImageIcon("settingsButton.png"));
        btnSettings.setPressedIcon(new ImageIcon("settingsButton.png"));
        btnSettings.addActionListener(new ButtonListener());

        
        /* Go to Patients Button */
        btnPatients = new JButton(new ImageIcon("patientsButton2.png"));
        btnPatients.setBounds(188,108,102,60);
        btnPatients.setBorderPainted(false);
        btnPatients.setContentAreaFilled(false);
        btnPatients.setRolloverIcon(new ImageIcon("patientsButton.png"));
        btnPatients.setPressedIcon(new ImageIcon("patientsButton.png"));
        btnPatients.addActionListener(new ButtonListener());

        
        /* Go to Appointments Button */
        btnAppointments = new JButton(new ImageIcon("appointmentsButton2.png"));
        btnAppointments.setBounds(290,108,151,60);
        btnAppointments.setBorderPainted(false);
        btnAppointments.setContentAreaFilled(false);
        btnAppointments.setRolloverIcon(new ImageIcon("appointmentsButton.png"));
        btnAppointments.setPressedIcon(new ImageIcon("appointmentsButton.png"));
        btnAppointments.addActionListener(new ButtonListener());

        
        /* Go to Services Button */
        btnServices = new JButton(new ImageIcon("servicesButton2.png"));
        btnServices.setBounds(440,108,100,60);
        btnServices.setBorderPainted(false);
        btnServices.setContentAreaFilled(false);
        btnServices.setRolloverIcon(new ImageIcon("servicesButton.png"));
        btnServices.setPressedIcon(new ImageIcon("servicesButton.png"));
        btnServices.addActionListener(new ButtonListener());
        
        
        /* To know the page the software is on.*/
        switch(MainFrame.page){
               case 1:
                    btnHome.setIcon(new ImageIcon("homeButton.png"));
                    break;
               case 2:
                    btnSettings.setIcon(new ImageIcon("settingsButton.png"));
                    
                    /*Change Password Button*/
                    btnChangePassword = new JButton("Change Password");
                    btnChangePassword.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnChangePassword.setForeground(Color.white);
                    btnChangePassword.setBounds(3,180,170,20);
                    btnChangePassword.setHorizontalAlignment(SwingConstants.LEFT);
                    btnChangePassword.setBorderPainted(false);
                    btnChangePassword.setContentAreaFilled(false);
                    MainFrame.panel.add(btnChangePassword);
                    
                    /*Logout Button*/
                    btnLogout = new JButton("Logout");
                    btnLogout.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnLogout.setForeground(Color.white);
                    btnLogout.setBounds(160,180,100,20);
                    btnLogout.setHorizontalAlignment(SwingConstants.LEFT);
                    btnLogout.setBorderPainted(false);
                    btnLogout.setContentAreaFilled(false);
                    btnLogout.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnLogout);
                    
                    break;
                    
               case 3:
                    btnPatients.setIcon(new ImageIcon("patientsButton.png"));
                    
                    /*View Patients Button*/
                    btnViewPatients = new JButton("View Patients");
                    btnViewPatients.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnViewPatients.setForeground(Color.white);
                    btnViewPatients.setBounds(3,180,150,20);
                    btnViewPatients.setHorizontalAlignment(SwingConstants.LEFT);
                    btnViewPatients.setBorderPainted(false);
                    btnViewPatients.setContentAreaFilled(false);
                    btnViewPatients.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnViewPatients);
                    
                    /*Register New Patient Button*/
                    btnRegisterPatients = new JButton("Register New Patient");
                    btnRegisterPatients.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnRegisterPatients.setForeground(Color.white);
                    btnRegisterPatients.setBounds(160,180,200,20);
                    btnRegisterPatients.setHorizontalAlignment(SwingConstants.LEFT);
                    btnRegisterPatients.setBorderPainted(false);
                    btnRegisterPatients.setContentAreaFilled(false);
                    btnRegisterPatients.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnRegisterPatients);
                    
                    break;
               case 4:
                    btnAppointments.setIcon(new ImageIcon("appointmentsButton.png"));
                    
                     /*View Appointments Button*/
                    btnViewAppointments = new JButton("View Appointments");
                    btnViewAppointments.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnViewAppointments.setForeground(Color.white);
                    btnViewAppointments.setBounds(3,180,175,20);
                    btnViewAppointments.setHorizontalAlignment(SwingConstants.LEFT);
                    btnViewAppointments.setBorderPainted(false);
                    btnViewAppointments.setContentAreaFilled(false);
                    btnViewAppointments.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnViewAppointments);
                    
                    /*Schedule New Appointment Button*/
                    btnScheduleNewAppointment = new JButton("Schedule New Appointment");
                    btnScheduleNewAppointment.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnScheduleNewAppointment.setForeground(Color.white);
                    btnScheduleNewAppointment.setBounds(160,180,250,20);
                    btnScheduleNewAppointment.setHorizontalAlignment(SwingConstants.LEFT);
                    btnScheduleNewAppointment.setBorderPainted(false);
                    btnScheduleNewAppointment.setContentAreaFilled(false);
                    btnScheduleNewAppointment.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnScheduleNewAppointment);
                    
                    break;
                    
                    
               case 5:
                    btnServices.setIcon(new ImageIcon("servicesButton.png"));
                    
                     /*View Services Button*/
                    btnViewServices = new JButton("View Services");
                    btnViewServices.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnViewServices.setForeground(Color.white);
                    btnViewServices.setBounds(3,180,175,20);
                    btnViewServices.setHorizontalAlignment(SwingConstants.LEFT);
                    btnViewServices.setBorderPainted(false);
                    btnViewServices.setContentAreaFilled(false);
                    btnViewServices.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnViewServices);
                    
                    /*Add New Service Button*/
                    btnAddNewService = new JButton("Add New Service");
                    btnAddNewService.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 16));
                    btnAddNewService.setForeground(Color.white);
                    btnAddNewService.setBounds(160,180,250,20);
                    btnAddNewService.setHorizontalAlignment(SwingConstants.LEFT);
                    btnAddNewService.setBorderPainted(false);
                    btnAddNewService.setContentAreaFilled(false);
                    btnAddNewService.addActionListener(new FunctionsListener());
                    MainFrame.panel.add(btnAddNewService);
        }
        
        MainFrame.panel.add(btnHome);
        MainFrame.panel.add(btnSettings);
        MainFrame.panel.add(btnPatients);
        MainFrame.panel.add(btnAppointments);
        MainFrame.panel.add(btnServices);
  }
  
  public class ButtonListener implements ActionListener{
     /* Buttons of the Main Headers */
     public void actionPerformed(ActionEvent e){
         
       MainFrame.panel.removeAll();
       
       if(e.getSource() == btnHome){
           MainFrame.page = 1;
           MainFrame.homePage.Draw();
           Draw();
       }
       else if(e.getSource() == btnSettings){
           MainFrame.page = 2;
           MainFrame.settingsPage.Draw();
           Draw();
       }
       else if(e.getSource() == btnPatients){           
           MainFrame.page = 3;
           MainFrame.patientsPage.page = 1;
           MainFrame.patientsPage.Draw();
           Draw();
       }
       else if(e.getSource() == btnAppointments){
           MainFrame.page = 4;
           MainFrame.appointmentsPage.page = 1;
           MainFrame.appointmentsPage.Draw();
           Draw();
       }
       else if(e.getSource() == btnServices){
           MainFrame.page = 5;
           MainFrame.servicesPage.page = 1;
           MainFrame.servicesPage.Draw();
           Draw();
       }

       MainFrame.panel.add(MainFrame.backgroundImage);
       MainFrame.panel.repaint();
     }
   }
   
   public class FunctionsListener implements ActionListener{
     /* Buttons of the sub Headers */
     public void actionPerformed(ActionEvent e){
        if(e.getSource() == btnLogout){
            
           JDialog.setDefaultLookAndFeelDecorated(false);
           int response = JOptionPane.showConfirmDialog(null, "Do you really want to end your session?", "End Session",
           JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
           if (response == JOptionPane.YES_OPTION){
               MainFrame.panel.removeAll();
               MainFrame.page = 1;
               MainFrame.loginPage.Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
           }
        }
        else if(e.getSource() == btnViewPatients){
               /* Go to View Patients Page */
               MainFrame.patientsPage.page = 1;
               
               MainFrame.panel.removeAll();
               MainFrame.page = 3;
               MainFrame.patientsPage.Draw();
               Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
        }
        else if(e.getSource() == btnRegisterPatients){
               /* Go to Register Patients Page */
               MainFrame.patientsPage.page = 3;
               
               MainFrame.panel.removeAll();
               MainFrame.page = 3;
               MainFrame.patientsPage.Draw();
               Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
        }
        else if(e.getSource() == btnViewAppointments){
               /* Go to View Appointments Page */
               MainFrame.appointmentsPage.page = 1;
               
               MainFrame.panel.removeAll();
               MainFrame.page = 4;
               MainFrame.appointmentsPage.Draw();
               Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
        }
        else if(e.getSource() == btnScheduleNewAppointment){
               /* Go to Schedule Appointment Page */
               MainFrame.appointmentsPage.page = 3;
               
               MainFrame.panel.removeAll();
               MainFrame.page = 4;
               MainFrame.appointmentsPage.Draw();
               Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
        }
        else if(e.getSource() == btnViewServices){
               /* Go to View Services Page */
               MainFrame.servicesPage.page = 1;
               
               MainFrame.panel.removeAll();
               MainFrame.page = 5;
               MainFrame.servicesPage.Draw();
               Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
        }
        else if(e.getSource() == btnAddNewService){
               /* Go to Add Service Page */
               MainFrame.servicesPage.page = 3;
               
               MainFrame.panel.removeAll();
               MainFrame.page = 5;
               MainFrame.servicesPage.Draw();
               Draw();
               MainFrame.panel.add(MainFrame.backgroundImage);
               MainFrame.panel.repaint();         
        }
        
        
     }
   }
   
   
   
}
